import * as CryptoJS from 'crypto-js';

const cryptoSecret: string = "__Shalamayne-Key__";

export function encrypt(data: any): string {
    return CryptoJS.AES.encrypt(JSON.stringify(data), cryptoSecret).toString();
}

export function decrypt(cipherText: string) {
    const bytes = CryptoJS.AES.decrypt(cipherText, cryptoSecret);
    const originalText = bytes.toString(CryptoJS.enc.Utf8);
    return originalText ? JSON.parse(originalText) : null;
}

export function md5(data: any) {
    return CryptoJS.MD5(JSON.stringify(data)).toString();
}
